using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MyAccount : System.Web.UI.UserControl
{
    processUser pUser;
    protected void Page_Load(object sender, EventArgs e)
    {
        pUser = new processUser();
        if (Session["userName"] == null || Session["userName"].ToString().Equals(""))
        {

            Response.Redirect("index.aspx?subpara=login");
        }
        Load_UserDetail(Session["userName"].ToString(), Session["Password"].ToString());
    }

    public void Load_UserDetail(string UserName, string Password)
    {
        string UserID = pUser.getUserID1(UserName, Password);
        DataTable dtUser = pUser.getUserDetail(UserName);       
        txtFullName.Text = dtUser.Rows[0]["FullName"].ToString();        
        txtEmail.Text = dtUser.Rows[0]["Email"].ToString();
        txtFoneNumber.Text = dtUser.Rows[0]["FoneNumber"].ToString();        
        DateTime dBirthDate = (DateTime)dtUser.Rows[0]["Birthday"];
        ddlDate.SelectedValue = dBirthDate.Day.ToString();
        ddlMonth.SelectedValue = dBirthDate.Month.ToString();
        ddlYear.SelectedValue = dBirthDate.Year.ToString();
        //txtAddress.Text = dtUser.Rows[0]["Address"].ToString();
        txtAddress.Text = dtUser.Rows[0]["Address"].ToString();
    }
   
    protected void btnReset_Click(object sender, EventArgs e)
    {
        txtFullName.Text = "";
        txtEmail.Text = "";
        txtFoneNumber.Text = "";        
        ddlDate.SelectedIndex = 0;
        ddlMonth.SelectedIndex = 0;
        ddlYear.SelectedIndex = 0;
        txtAddress.Text = "";
        txtFullName.Focus();
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            string UserName = Session["UserName"].ToString();
            string Password = Session["Password"].ToString();
            string UserID = pUser.getUserID1(UserName, Password);
            string FullName = txtFullName.Text;
            string Email = txtEmail.Text;
            string FoneNumber = txtFoneNumber.Text;
            DateTime Birthday = DateTime.Parse(ddlDate.SelectedValue + "/" + ddlMonth.SelectedValue + "/" + ddlYear.SelectedValue);
            string Address = txtAddress.Text;
            if (pUser.updateCustomer(UserID, FullName, Birthday, Address, FoneNumber, Email) > 0)
            {
                Response.Write("<script>alert('Update successfull!')</script>");
                Response.Redirect("index.aspx");
            }
            else
            {
                Response.Write("<script>alert('Update unsuccessfull!')</script>");
                Response.Redirect("index.aspx?subpara=createaccount");
            }
        }
        catch (Exception ex)
        {
            
            Response.Write(ex.Message);
        }
    }
}
